package com.service.impl;

import com.bean.entity.MaterialClassification;
import com.dao.MaterialClassificationMapper;
import com.service.MaterialClassificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 供应商分类信息实现
 */
@Service
public class MaterialClassificationServiceImpl implements MaterialClassificationService {

    //自动注入
    @Autowired
    MaterialClassificationMapper materialClassificationMapper;

    @Override
    public List<MaterialClassification> queryAll(MaterialClassification mat) {
        return materialClassificationMapper.select(mat);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int modify(MaterialClassification mat) throws Exception {
        //修改信息
        int i = materialClassificationMapper.update(mat);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("修改失败！");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int remove(MaterialClassification mat) throws Exception {
        //修改信息
        int i = materialClassificationMapper.delete(mat);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("删除失败！");
        }
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int save(MaterialClassification mat) throws Exception {
        //修改信息
        int i = materialClassificationMapper.insert(mat);
        if(i == 1){
            return 1;
        }else{
            throw new Exception("添加失败！");
        }
    }
}
